package com.threegroup.admin.controller;

import com.github.pagehelper.PageInfo;
import com.threegroup.admin.annotation.AuthorityVerify.AuthorityVerify;
import com.threegroup.common.utils.Result;
import com.threegroup.admin.entity.AddressBookEntity;
import com.threegroup.admin.service.AddressBookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *    功能                       请求方式         请求参数
 * 保存地址                        POST           addressBookDTO
 * 修改默认地址                    PUT            addressBookDTO
 * 删除地址                        DELETE         id
 * 根据用户ID查询所有地址          GET            addressBookDTO
 * 地址详细信息                    GET            id
 */
@RestController
@RequestMapping("takeout/addressbook")
public class AddressBookController {
    @Resource
    private AddressBookService addressBookService;


    /**
     * 保存地址
     * POST
     * addressBookDTO
     */
    @PostMapping
    public Result add(@RequestBody AddressBookEntity addressBookDTO){
        return addressBookService.add(addressBookDTO);
    }

    /**
     * 修改默认地址
     * PUT
     * addressBookDTO
     */
    @PutMapping
    public Result updateAddr(@RequestBody AddressBookEntity addressBookDTO){
        return addressBookService.update(addressBookDTO);
    }

    /**
     * 删除地址
     * DELETE
     * id
     */
    @DeleteMapping
    public Result deleteAdrr(@RequestBody Long[] ids){
//        String id = request.getHeader("id");
//        System.out.println(id);
        return addressBookService.delete(ids);
    }

    /**
     * 分页
     * GET
     * addressBookDTO
     */
    @GetMapping("page")
    public Result<PageInfo<AddressBookEntity>> getList(Integer limit, Integer page, String order, String orderField,String id){
        Result<PageInfo<AddressBookEntity>> result= addressBookService.getPageList(limit,page,order,orderField,id);
        return result;
    }

    /**
     * 删除地址
     * DELETE
     * id
     */
    @GetMapping("{id}")
    public Result info(@PathVariable Long id){
        return addressBookService.info(id);
    }
}
